package Dame;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class test5 {
    public static void main(String[] args) {
        Map<student, String> map = new HashMap<>();
        student s1 = new student("小鲁", 19);
        student s2 = new student("中鲁", 20);
        student s3 = new student("大鲁", 21);

        map.put(s1, "湖南");
        map.put(s2, "平江");
        map.put(s3, "岳阳");

        Set<student> ss1 = map.keySet();
        for (student key : ss1) {
            String s = map.get(key);
            System.out.println(key + "----" + s);
        }
        System.out.println("---------------");
        Set<Map.Entry<student, String>> entries = map.entrySet();
        for (Map.Entry<student, String> entry : entries) {
            student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "----" + value);
        }
        System.out.println("---------------");
        map.forEach((
                student key,String value
        ) -> {
            System.out.println(key + "----" + value);
        });
        System.out.println("---------------");
        Set<Map.Entry<student, String>> entries1 = map.entrySet();
        Iterator<Map.Entry<student, String>> iterator = entries1.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}

class student {
    private String name;
    private int age;

    public student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        student student = (student) o;

        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
